#include <iostream>
#include <cstring>

using namespace std;
// #define ONLINE_JUDGE
const int N = 3e5 + 10;

int n, m; 
int s[N];
int q[N]; // 滑动窗口队列

int main() {

    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);   
	cin.tie(0);

    cin >> n >> m;
    for(int i = 1; i <= n; i++)
    {
        cin >> s[i]; s[i] += s[i-1];
    }

    int ans = -1e18; // 结果可能为负数
    int hh = 0, tt = 0; // 下标

    for(int i = 1; i <= n; i++)
    {
        if(q[hh] < i - m) hh++; // 
        ans = max(ans, s[i] - s[q[hh]]);
        while(hh <= tt && s[q[tt]] >= s[i]) tt--;
        q[++tt] = i;
    }

    cout << ans << endl;
    return 0;
}
